package com.ruoyi.data.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.data.domain.bo.Devices.*;
import com.ruoyi.data.domain.vo.DataListVo;
import com.ruoyi.data.domain.vo.Devices.SelectTypeVo;
import com.ruoyi.data.domain.vo.Devices.StatisticsVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.data.domain.vo.Devices.DevicesVo;
import com.ruoyi.data.service.IDevicesService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备
 *
 * @author ruoyi
 * @date 2024-10-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/devices/devices")
public class DevicesController extends BaseController {

    private final IDevicesService iDevicesService;

    /**
     * 查询统计数据
     * @return
     */
    @PostMapping ("/queryingStatistics")
    //@SaCheckPermission("devices:devices:queryingStatistics")
    public R<StatisticsVo> queryingStatistics(@RequestBody StatisticsBo bo) {
        return R.ok(iDevicesService.queryingStatistics(bo));
    }


    /**
     * 按照类别查询所需的下拉数据
     * @param bo
     * @return
     */
    //@SaCheckPermission("devices:devices:selectTypeList")
    @PostMapping("/selectTypeList")
    public List<SelectTypeVo> selectTypeList(@RequestBody SelectTypeBo bo) {
        return iDevicesService.selectTypeList(bo);
    }


    /**
     * 查询设备列表
     */
    //@SaCheckPermission("devices:devices:list")
    @GetMapping("/list")
    public TableDataInfo<DevicesVo> list(DevicesBo bo, PageQuery pageQuery) {
        return iDevicesService.queryPageList(bo, pageQuery);
    }


    /**
     * 查询数据列表不分页
     */
    //@SaCheckPermission("devices:devices:noPageList")
    @PostMapping("/noPageList")
    public R<List<DevicesVo>> noPageList(@RequestBody SelectNoPageBo bo) {
        return R.ok(iDevicesService.noPageList(bo));
    }

    /**
     * 导出设备列表
     */
    //@SaCheckPermission("devices:devices:export")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DevicesBo bo, HttpServletResponse response) {
        List<DevicesVo> list = iDevicesService.queryList(bo);
        ExcelUtil.exportExcel(list, "设备", DevicesVo.class, response);
    }


    /**
     * 修改设备
     */
    //@SaCheckPermission("devices:devices:edit")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody List<UpdateDevicesBo> bo) {
        return toAjax(iDevicesService.updateByBo(bo));
    }

    /**
     * 删除设备
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("devices:devices:remove")
    @Log(title = "设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iDevicesService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    /**
     * 获取外部count接口
     *
     */
    @PostMapping ("/getPhpCount")
    //@SaCheckPermission("devices:devices:getPhpCount")
    public R<String> getPhpCount(@RequestBody StatisticsBo bo){
        return R.ok("ok", iDevicesService.getPhpCount(bo));
    }
}
